Highcharts.setOptions({
	global: {
		useUTC: false
	}
});

var winBaseInfoName = {
	sttp: "测站类型：",
	dtmnm: "基面名称：",
	admauth: "管理机构：",
	drna: "集水面积：",
	rvnm: "河流名称：",
	frgrd: "报汛等级：",
	bsnm: "流域名称：",
	hnnm: "水系名称：",
	esstym: "建站年月：",
	bgfrym: "始报年月："
}

var chartOption = {
	chart: {
		zoomType: 'x'
	},
	exporting: {
		enabled: false
	},
	xAxis: {
		type: 'datetime',
		dateTimeLabelFormats: {
			day: '%m-%d',
			week: '%m-%d',
			month: '%y-%m-%d',
			year: '%y-%m-%d'
		}
	},
	yAxis: {
		lineWidth: 1
	},
	credits: {
		enabled: false
	},
	legend: {
		verticalAlign: 'bottom'
	},
	plotOptions: {
		series: {
			marker: {
				enabled: false
			}
		}
	},
	tooltip: {
		shared: true,
		crosshairs: true,
		dateTimeLabelFormats: {
			second: '%m-%d %H:%M',
			minute: '%m-%d %H:%M',
			hour: '%m-%d %H:%M',
			day: '%m-%d',
			week: '%m-%d',
			month: '%y-%m-%d',
			year: '%y-%m-%d'
		}
	}
}

function showInProvOrCity() {
	var inProvOrCityLable = $('.inProvOrInCity');
	var groupId = getCookie("groupId");
	if (groupId == 1) {
		inProvOrCityLable.append(" 省外");
	} else if (groupId == 2) {
		inProvOrCityLable.append(" 市外");
	}
}

function getCookie(cookie_name) {
	var allcookies = document.cookie;
	var cookie_pos = allcookies.indexOf(cookie_name); //索引的长度
	// 如果找到了索引，就代表cookie存在，
	// 反之，就说明不存在。
	if (cookie_pos != -1) {
		// 把cookie_pos放在值的开始，只要给值加1即可。
		cookie_pos += cookie_name.length + 1; //这里我自己试过，容易出问题，所以请大家参考的时候自己好好研究一下。。。
		var cookie_end = allcookies.indexOf(";", cookie_pos);
		if (cookie_end == -1) {
			cookie_end = allcookies.length;
		}
		var value = unescape(allcookies.substring(cookie_pos, cookie_end)); //这里就可以得到你想要的cookie的值了。。。
	}
	return value;
}

function exportToCsv(csvDatas) {
	if ($.isEmptyObject(csvDatas)) {
		return;
	}

	var exportGridForm = $('#exportGridForm');
	var form = $('<form></form>');
	exportGridForm.append(form);
	form.attr('action', '../gis/GridExportCsv.do?method=export');
	form.attr('method', 'post');

	var csvDataInput = $('<input type="text" name="csvDatas" />');
	csvDataInput.val(csvDatas);
	form.append(csvDataInput);

	form.submit();
	form.remove();
}

function exportToCsvByBtn(windowContent) {
	$('#exportCsvBtn').on('click', function() {
		var showTablePanel = windowContent.children('.tab-content').children('.active');
		var callType = showTablePanel.data('callType');
		if (callType == 'layerRain') {
			callType = 'rain';
		}

		var csvDatas = showTablePanel.find('.dataPanel .active .' + callType + ' table').data('csvDatas');
		if ($.isEmptyObject(csvDatas)) {
			return;
		}

		var exportGridForm = $('#exportGridForm');
		var form = $('<form></form>');
		exportGridForm.append(form);
		form.attr('action', '../gis/GridExportCsv.do?method=export');
		form.attr('method', 'post');

		var csvDataInput = $('<input type="text" name="csvDatas" />');
		csvDataInput.val(csvDatas);
		form.append(csvDataInput);

		form.submit();
		form.remove();
	});
}

function buildWinBaseInfo(data) {
	var content = $('<tbody></tbody>');
	for (var key in winBaseInfoName) {
		var name = winBaseInfoName[key];
		var val = data[key] == null ? '' : data[key];
		content.append('<tr><th>' + name + '</th><td>' + val + '</td></tr>');
	}
	return content;
}

function buildRiverWinRsvrfcch(data) {
	for (var i in data) {
		if (data[i] == null || data[i] === undefined) {
			data[i] = '';
		}
	}
	var content = $('<tbody></tbody>');
	content.append('<tr><th>' + '左堤高程' + '</th><td>' + data.ldkel + '</td><th>' + '右堤高程' + '</th><td>' + data.rdkel + '</td></tr>');
	content.append('<tr><th>' + '警戒水位' + '</th><td>' + data.wrz + '</td><th>' + '警戒流量' + '</th><td>' + data.wrq + '</td></tr>');
	content.append('<tr><th>' + '保证水位' + '</th><td>' + data.grz + '</td><th>' + '保证流量' + '</th><td>' + data.grq + '</td></tr>');
	content.append('<tr><th>' + '平摊流量' + '</th><td>' + data.flpq + '</td><th>' + ' ' + '</th><td>' + ' ' + '</td></tr>');
	content.append('<tr><th>' + '实测最高水位' + '</th><td>' + data.obhtz + '</td><th>' + '实测最高水位出现时间' + '</th><td>' + data.obhtzTm + '</td></tr>');
	content.append('<tr><th>' + '调查最高水位' + '</th><td>' + data.ivhz + '</td><th>' + '调查最高水位出现时间' + '</th><td>' + data.ivhzTm + '</td></tr>');
	content.append('<tr><th>' + '实测最大流量' + '</th><td>' + data.obmxq + '</td><th>' + '实测最大流量出现时间' + '</th><td>' + data.obmxqTm + '</td></tr>');
	content.append('<tr><th>' + '调查最大流量' + '</th><td>' + data.ivmxq + '</td><th>' + '调查最大流量出现时间' + '</th><td>' + data.ivmxqTm + '</td></tr>');
	content.append('<tr><th>' + '历史最大含沙量' + '</th><td>' + data.hmxs + '</td><th>' + '历史最大含沙量出现时间' + '</th><td>' + data.hmxsTm + '</td></tr>');
	content.append('<tr><th>' + '历史最大断面平均流速' + '</th><td>' + data.hmxavv + '</td><th>' + '历史最大断面平均流速出现时间' + '</th><td>' + data.hmxavvTm + '</td></tr>');
	content.append('<tr><th>' + '历史最低水位' + '</th><td>' + data.hlz + '</td><th>' + '历史最低水位出现时间' + '</th><td>' + data.hlzTm + '</td></tr>');
	content.append('<tr><th>' + '历史最小流量' + '</th><td>' + data.hmnq + '</td><th>' + '历史最小流量出现时间' + '</th><td>' + data.hmnqTm + '</td></tr>');
	return content;
}

function buildReservoirRsvrfcch(data) {
	for (var i in data) {
		if (data[i] == null || data[i] === undefined) {
			data[i] = '';
		}
	}
	var content = $('<tbody></tbody>');
	content.append('<tr><th>' + '坝顶高程' + '</th><td>' + data.damel + '</td><th>' + '校核洪水位' + '</th><td>' + data.ckflz + '</td></tr>');
	content.append('<tr><th>' + '设计洪水位' + '</th><td>' + data.dsflz + '</td><th>' + '正常高水位' + '</th><td>' + data.normz + '</td></tr>');
	content.append('<tr><th>' + '死水位' + '</th><td>' + data.ddz + '</td><th>' + '兴利水位' + '</th><td>' + data.actz + '</td></tr>');
	content.append('<tr><th>' + '总库容' + '</th><td>' + data.ttcp + '</td><th>' + '防洪库容' + '</th><td>' + data.fldcp + '</td></tr>');
	content.append('<tr><th>' + '兴利库容' + '</th><td>' + data.actcp + '</td><th>' + '死库容' + '</th><td>' + data.ddcp + '</td></tr>');
	content.append('<tr><th>' + '历史最高库水位' + '</th><td>' + data.hhrz + '</td><th>' + '历史最高库水位出现时间' + '</th><td>' + data.hhrzTm + '</td></tr>');
	content.append('<tr><th>' + '历史最大入流' + '</th><td>' + data.hmxinq + '</td><th>' + '历史最大入流出现时间' + '</th><td>' + data.hmxinqTm + '</td></tr>');
	content.append('<tr><th>' + '历史最大入流还原时段' + '</th><td>' + data.rstdr + '</td><th>' + ' ' + '</th><td>' + ' ' + '</td></tr>');
	content.append('<tr><th>' + '历史最大蓄量' + '</th><td>' + data.hmxw + '</td><th>' + '历史最大蓄量出现时间' + '</th><td>' + data.hmxwTm + '</td></tr>');
	content.append('<tr><th>' + '水库历史最大出流' + '</th><td>' + data.rhmxotq + '</td><th>' + '水库历史最大出流出现时间' + '</th><td>' + data.rhmxotqTm + '</td></tr>');
	return content;
}

function plHoverStyle(e) {
	$(this).css("background-color", e.type === "mouseenter" ? "rgb(206, 219, 239)" : "transparent");
}

function plShow() {
	var $_this = $(this);
	var title = $_this.data('title');
	var imgTitle = $_this.data('imgTitle');
	var jsz = $_this.data('jsz');
	var viewDatas = $_this.data('viewDatas');
	var cs = 0,
		cv = 0;
	var data = [];
	var plImg = $('#plImg');

	var plFreeSet = $('#plFreeSet');
	var historyViewDatas = $('#historyViewDatas');
	var sjzViewDatas = $('#sjzViewDatas');
	var cxzSpan = $('#cxzSpan');
	var drawPl = $('#drawPl');

	$('#jszSpan').text(jsz);
	var historyTableTrs = [];
	for (var index in viewDatas) {
		var viewData = viewDatas[index];
		if (viewData != null) {
			data.push(viewData.val);
		}
		historyTableTrs[index] = $('<tr><td>' + (parseInt(index) + 1) + '</td><td>' + viewData.tm + '</td><td>' + viewData.val + '</td></tr>');
	}

	data = data.length > 0 ? data.join(' ') : '';
	var sliderOption = {
		min: 0,
		step: 0.01,
		hide_min_max: true,
		hide_from_to: false,
		grid: false,
		disable: true
	};

	var cvSliderOption = $.extend({}, sliderOption, {
		max: 2,
		from: cv,
		onFinish: function(data) {
			cv = data.from;
		}
	});
	var csSliderOption = $.extend({}, sliderOption, {
		max: 4,
		from: cs,
		onFinish: function(data) {
			cs = data.from;
		}
	});
	var $_cvSlider = $("#cvSlider"),
		$_csSlider = $("#csSlider");

	if (!$_cvSlider.prop('readonly') && !$_cvSlider.prop('readonly')) {
		jQuery.pl = {};
		$_cvSlider.ionRangeSlider(cvSliderOption);
		jQuery.pl.cvSlider = $_cvSlider.data("ionRangeSlider");

		$_csSlider.ionRangeSlider(csSliderOption);
		jQuery.pl.csSlider = $_csSlider.data("ionRangeSlider");
	} else if (jQuery.pl && jQuery.pl.cvSlider && jQuery.pl.csSlider) {
		jQuery.pl.cvSlider.update(cvSliderOption);
		jQuery.pl.csSlider.update(csSliderOption);
		jQuery.pl.csSlider.reset();
		jQuery.pl.cvSlider.reset();
	}

	plFreeSet.on('change', function() {
		var isChoose = $(this).prop('checked');
		jQuery.pl.cvSlider.update({
			disable: !isChoose
		});
		jQuery.pl.cvSlider.reset();

		jQuery.pl.csSlider.update({
			disable: !isChoose
		});
		jQuery.pl.csSlider.reset();
	});

	drawPl.on('click', function() {
		getPlImg();
	});

	historyViewDatas.on('click', function() {
		var historyTable = $("#historyTable");
		historyTable.find('table>tbody').remove();
		if (historyTableTrs.length < 10) {
			for (var i = historyTableTrs.length; i <= 10; i++) {
				historyTableTrs[i] = $('<tr style="height:22px"><td></td><td></td><td></td></tr>');
			}
		}
		historyTable.find('table').append($('<tbody></tbody>').append(historyTableTrs));
		$.buildDialog({
			$_this: $(this),
			target: historyTable,
			title: '历史序列',
			modal: true,
			width: 200,
			height: 350
		});
		return false;
	});

	sjzViewDatas.on('click', function() {
		//		alert('asv');
	});

	function getPlImg() {
		var id = new Date().getTime();
		$.post('../gis/PinLvScreen.json?method=drawPl', {
			data: data,
			cs: cs,
			cv: cv,
			title: imgTitle,
			id: id,
			jsz: jsz
		}, function(path) {
			plImg.attr('src', path);
		});
	}
	plImg.attr('src', 'plImg/pinlv.png?t' + new Date().getTime());
	plFreeSet.removeAttr('checked');
	getPlImg();

	var params = {
		$_this: $(this),
		target: $('#plWindow'),
		title: title,
		modal: true,
		width: 780,
		height: 630,
		close: function() {
			// 注销事件
			historyViewDatas.off();
			sjzViewDatas.off();
			plFreeSet.off();
			drawPl.off();
			$(this).dialog('destroy');
		}
	};

	$.buildDialog(params);
	return false;
}

function showWindow(showTabPanel) {
	var callType = showTabPanel.data('callType');
	var stcd = showTabPanel.data('stcd');
	var stnm = showTabPanel.data('stnm');
	var isload = showTabPanel.data('isload');
	if (!isload) {
		var showPanelId = showTabPanel.attr('id');
		// 设置窗口时间
		setWindowVals(showTabPanel, showPanelId);
		if (callType == 'layerRain') {
			callType = 'rain';
		}
		// 注册查询按钮事件
		var a = callType.charAt(0).toUpperCase();
		var b = callType.substr(1);
		$('#windowQuery', showTabPanel).off();
		$('#windowQuery', showTabPanel).on('click', {
			panel: showTabPanel
		}, window['window' + a + b + 'Query']);

		// 标记已加载
		showTabPanel.data('isload', 1);
		// 触发查询按钮事件
		$('#windowQuery', showTabPanel).trigger('click');
	}
}

function setWindowVals(showTabPanel, showPanelId) {
	var now = new Date();
	var startTime, endTime = $.format.date(now, 'yyyy-MM-dd');

	if (showPanelId == 'day') {
		var month = now.getMonth();
		var startDate = new Date(now.setMonth(month - 3));
		startTime = $.format.date(startDate, 'yyyy-MM-dd');
	} else if (showPanelId == 'hour') {
		var date = now.getDate();
		var startDate = new Date(now.setDate(date - 10));
		startTime = $.format.date(startDate, 'yyyy-MM-dd');
	}

	showTabPanel.find('input[name="startTime"]').val(startTime);
	showTabPanel.find('input[name="endTime"]').val(endTime);

	// 使用当前输入框中的值更新日期时间选择器
	showTabPanel.find('.form_date').datetimepicker('update');
}

function getWindowVals(showTabPanel, haveDxn, haveExKey) {
	var startTime = showTabPanel.find('input[name="startTime"]').val();
	var endTime = showTabPanel.find('input[name="endTime"]').val();
	var result = {
		startTime: startTime,
		endTime: endTime,
		stcd: showTabPanel.data('stcd'),
		stnm: showTabPanel.data('stnm')
	}
	if (haveDxn) {
		var dxn = showTabPanel.find('select[name="dxn"]').val();
		$.extend(result, {
			dxn: dxn
		});
	}
	if (haveExKey) {
		var exKey = showTabPanel.find('select[name="exKey"]').val();
		$.extend(result, {
			exKey: exKey
		});
	}

	return result;
}

function buildChart(showTabPanel, startDate, chartOption, chartParams, sendParams, showPanelId, windowType) {
	var tmpChartOption = $.extend(true, {}, chartOption);
	var pointInterval, pointStart;
	var seriesData = chartParams.seriesData;
	if (showPanelId == 'day') {
		if (windowType == 'groundWater' || windowType == 'moistrure') {
			pointInterval = 5 * 24 * 3600 * 1000; // 五天

		} else {
			pointInterval = 24 * 3600 * 1000; // 一天
		}
		pointStart = Date.UTC(startDate.getFullYear(), startDate.getMonth(), startDate.getDate());
	} else if (showPanelId == 'hour') {
		pointInterval = 3600 * 1000; // 小时
		if (windowType == 'water') {
			// 已经设置了全局GTM，这里需要-8小时
			pointStart = Date.UTC(startDate.getFullYear(), startDate.getMonth(), startDate.getDate(), -8);
		}
	}

	var chartTitle = chartParams.chartTitle;
	var subtitle = chartParams.subChartTitle;
	var name = chartParams.name;
	var url = chartParams.url;
	$.extend(tmpChartOption, {
		title: {
			text: ''
		}
	}, {
		subtitle: {
			text: ''
		}
	});

	$.get(url, sendParams, function(data) {
		var series = [];
		var chartData;
		if (windowType == 'groundWater' || windowType == 'moistrure') {
			if (data.startPoint != null) {
				var splitBTm = ($.format.date(data.startPoint, 'yyyy-MM-dd')).split('-');
				var startDate = new Date(splitBTm[0], splitBTm[1] - 1, splitBTm[2]);
				pointStart = Date.UTC(startDate.getFullYear(), startDate.getMonth(), startDate.getDate());
			}
		}
		for (var key in seriesData) {
			var val = seriesData[key];
			var visible = {};
			if (val.visible != undefined) {
				visible = {
					visible: val.visible
				};
			}
			if (windowType == 'groundWater' || windowType == 'moistrure') {
				chartData = data.result[val.dataVal];
			} else {
				chartData = data[val.dataVal];
			}
			var obj = {
				type: val.type,
				name: val.name,
				color: val.color,
				yAxis: val.yAxis,
				data: chartData
			}
			if (windowType == 'water') {
				obj = $.extend(obj, {
					pointStart: pointStart,
					pointInterval: pointInterval
				})
			}
			series.push($.extend(obj, visible));
		}

		$.extend(tmpChartOption, {
			series: series
		});
		if (showPanelId == 'hour' && windowType == 'water-Weirgates') {
			tmpChartOption.tooltip.crosshairs = false;
			tmpChartOption.tooltip.shared = false;
			// tmpChartOption.tooltip.pointFormat = "{series.name} : {point.y}"
			tmpChartOption.tooltip.formatter = function() {
				var date = new Date(this.x)
				var header = (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + (date.getMinutes() < 9 ? ('0' + date.getMinutes()) : date.getMinutes());
				return header + "<br/>" + '<span style="color:' + this.series.color + '">\u25CF</span> ' + this.series.name + ':' + this.y;
			}
			tmpChartOption.series[1].type = 'scatter';
			$.extend(tmpChartOption, {
				plotOptions: {
					line: {
						dataLabels: {
							enabled: true
						},
						enableMouseTracking: false
					}
				}
			})
		}
		$('#chart', showTabPanel).highcharts(tmpChartOption);
	});
}

function buildChart2(showTabPanel, startDate, chartOption, chartParams, sendParams, showPanelId, windowType) {
	var pointInterval, pointStart;
	var seriesData = chartParams.seriesData;
	if (showPanelId == 'day') {
		if(windowType== 'groundWater' ||windowType=='moistrure'){
			pointInterval = 5*24 * 3600 * 1000;// 五天
			
		}else{
			pointInterval = 24 * 3600 * 1000; // 一天
		}
		pointStart = Date.UTC(startDate.getFullYear(), startDate.getMonth(), startDate.getDate());
	} else if (showPanelId == 'hour') {
		pointInterval = 3600 * 1000; // 小时
		if(windowType == 'water'){
			pointStart = Date.UTC(startDate.getFullYear(), startDate.getMonth(), startDate.getDate());
		}else{
			pointStart = Date.UTC(startDate.getFullYear(), startDate.getMonth(), startDate.getDate(), -8);
		}
	}

	var chartTitle = chartParams.chartTitle;
	var subtitle = chartParams.subChartTitle;
	var name = chartParams.name;
	var url = chartParams.url;
	$.extend(chartOption, {
		title: {
			text: ''
		}
	}, {
		subtitle: {
			text: ''
		}
	});

	$.get(url, sendParams, function(data) {
		var series = [];
		var chartData;
		if(windowType== 'groundWater' ||windowType=='moistrure'){
			if(data.startPoint!=null){
				var splitBTm = ($.format.date(data.startPoint, 'yyyy-MM-dd')).split('-');
				var startDate = new Date(splitBTm[0],splitBTm[1] - 1,splitBTm[2]);
				pointStart=Date.UTC(startDate.getFullYear(), startDate.getMonth(), startDate.getDate());
			}
		}
		for (var key in seriesData) {
			var val = seriesData[key];
			var visible = {};
			if (val.visible != undefined) {
				visible = {
					visible: val.visible
				};
			}
			if(windowType== 'groundWater' ||windowType=='moistrure'){
				chartData=data.result[val.dataVal];
			}else{
				chartData=data[val.dataVal];
			}
			series.push($.extend({
				type: val.type,
				name: val.name,
				color: val.color,
				yAxis: val.yAxis,
				data: chartData,
				pointStart: pointStart,
				pointInterval: pointInterval
			}, visible));
		}

		$.extend(chartOption, {
			series: series
		});
		$('#chart', showTabPanel).highcharts(chartOption);
	});
}

function buildAnalysisTable(analysisTable, showTabPanel, params, sendParams, showPanelId, windowType) {
	var analysisTableUrl = params.analysisTableUrl;
	var warnDayNumKey = params.warnDayNumKey;
	var dataIndex = params.dataIndex;
	var fDataIndex = params.fDataIndex;
	var sotrHistory = params.sotrHistory;
	var maxMinAvg = params.maxMinAvg;
	var plMaxDateName = params.plMaxDateName;

	$.get(analysisTableUrl, sendParams, function(data) {
		if (windowType == 'water') {
			$('#warnDayLabel', showTabPanel).text('从' + sendParams.bTm + '到' + sendParams.eTm + '一共超警天数为' + data[warnDayNumKey] + '天');
		}
		var tbodyTrs = analysisTable.find('tbody tr');
		tbodyTrs.each(function(trIndex, trEle) {
			var $trEle = $(trEle);
			if ($trEle.find('td').length == 1) {
				if (windowType == 'water') {
					var haveFlow = params.haveFlow;
					var y = haveFlow ? 1 : 2;
					var cols = params.cols;

					if (trIndex == 2) { // 排位
						for (var i = 1; i <= cols[0]; i++) {
							var colspan = (i % 3 == 0 ? 1 : 2);
							$trEle.append('<td colspan="' + colspan + '"></td>');
						}
					} else {
						for (var i = 0; i < cols[1]; i++)
							$trEle.append('<td></td>');
					}
				} else if (windowType == 'rain') {
					if (trIndex == 2) { // 排位
						for (var i = 0; i < 5; i++)
							$trEle.append('<td colspan="2"></td>');
					} else {
						for (var i = 0; i < 10; i++)
							$trEle.append('<td></td>');
					}
				}
			}

			var dataTds = $trEle.find('td:gt(0)');
			var num = 0;
			dataTds.each(function(tdIndex, tdEle) {
				var $tdEle = $(tdEle);
				var key, key2;
				var isAvg = false;
				var index;
				if (trIndex != 2) {
					if (windowType == 'water') {
						if (tdIndex == 4 || tdIndex == 9) {
							isAvg = true;
						}
						if (tdIndex > 4) {
							tdIndex++;
						}
					}
					index = parseInt(tdIndex / 2);
				} else {
					index = tdIndex;
				}

				if (trIndex == 0) { // 当前
					key = dataIndex[index];
				} else if (trIndex == 1) { // 历史
					key = fDataIndex[index];
				} else if (trIndex == 2) { // 排位
					key = sotrHistory[index];
					key2 = maxMinAvg[index];
				}

				if (trIndex != 2) {
					if (isAvg) {
						var val = data[key].val == undefined ? data[key] : data[key].val
						$tdEle.text(val);
						isAvg = false;
					} else {
						if (num == 0) {
							$tdEle.text(data[key].val);
							num = 1;
						} else if (num == 1) {
							var tm = data[key].tm;
							$tdEle.text(tm ? tm : '');
							num = 0;
						}
					}
				} else {
					var jsz;
					if ((windowType == 'water' && (tdIndex != 3 || tdIndex != 6)) || windowType == 'rain') {
						jsz = (data[dataIndex[tdIndex]]).val; // 当前值
					} else if (windowType == 'water') {
						jsz = (data[dataIndex[tdIndex]]); // 当前值
					}
					var title = sendParams.bTm + '至' + sendParams.eTm + plMaxDateName[tdIndex] + '历年频率曲线以及重现期值';
					var imgTitle = params.stnm + plMaxDateName[tdIndex] + '频率曲线';
					$tdEle.css('text-decoration', 'underline').css('cursor', 'pointer');
					$tdEle.data('viewDatas', data[key2]).data('title', title).data('imgTitle', imgTitle).data('jsz', jsz);
					$tdEle.on('click', plShow);
					$tdEle.hover(plHoverStyle);
					$tdEle.text(data[key][0] + '/' + data[key][1]);
				}
			});
		});
	});
}

function buildTable(showTabPanel, params, sendParams, showPanelId, windowType) {
	var chartDataTableUrl = params.chartDataTableUrl;
	var callType = showTabPanel.data('callType');
	var findClass = callType;
	if (callType == 'layerRain') {
		findClass = 'rain';
	}
	var findId = showPanelId.charAt(0).toUpperCase();
	findId += showPanelId.substr(1);
	var chartDataTable = showTabPanel.find('#featureData' + findId + ' .' + findClass + ' table');
	var analysisTable = showTabPanel.find('#featureAnalysis' + findId + ' .' + findClass);
	var csvSplitChar = '||';

	// 特征数据
	if (analysisTable.length == 1) {
		buildAnalysisTable(analysisTable, showTabPanel, params, sendParams, showPanelId, windowType)
	}
	// 数据列表
	$.get(chartDataTableUrl, sendParams, function(data) {
		var body = chartDataTable.find('tbody');
		// 清空
		body.find('tr').remove();
		var csvDataHeaders = params.csvDataHeaders;
		var dataKeys = params.dataKeys;
		var dataKeySize = dataKeys.length;
		var csvDatas = csvDataHeaders + csvSplitChar;

		for (var index in data) {
			var val = data[index];
			var indexInt = parseInt(index);
			var csvLine = (indexInt + 1) + ',';
			var trLineHtml = '<tr>';
			for (var keyIndex in dataKeys) {
				var keyVal = dataKeys[keyIndex];
				var csvSplit = dataKeySize == parseInt(keyIndex) + 1 ? '' : ',';
				csvLine += (val[keyVal] + csvSplit);
				trLineHtml += ('<td>' + val[keyVal] + '</td>');
			}
			trLineHtml += '</tr>'
			body.append(trLineHtml);
			csvDatas += csvLine + csvSplitChar;
		}
		chartDataTable.data('csvDatas', csvDatas);
	});
}

function windowInit(winContent, callType) {
	var dyamicTab = $('.dataPanel li[role="presentation"],.dataPanel div[role="tabpanel"]', winContent);
	dyamicTab.removeClass('active').hide();

	var showOtherClass;
	// 导出按钮
	var exportCsvBtn = $('#exportCsvBtn', winContent);

	var allBtn = winContent.children('.btn');
	allBtn.hide();
	var showBtn = allBtn.filter('.' + callType).not(exportCsvBtn).show();
	var initRight = 13;
	var preBtnWidth = 0;
	showBtn.each(function(i, n) {
		var item = $(n);
		var right = (initRight * (i + 1)) + preBtnWidth;
		item.css('right', right + 'px');
		preBtnWidth = 64;
	});

	if (callType == 'rain' || callType == 'layerRain') {
		tabNames = ['日降雨过程', '小时降雨过程'];
		callType = 'rain';
	} else if (callType == 'river' || callType == 'weirgates') {
		tabNames = ['日水位过程', '实时水位过程'];
		showOtherClass = 'dxnClass';
	} else if (callType == 'reservoir' || callType == 'pump') {
		tabNames = ['逐日8时水位过程', '实时水位过程'];
		showOtherClass = 'dxnClass';
	} else if (callType == 'tide') {
		tabNames = ['逐日8时潮位过程', '实时潮位过程'];
		showOtherClass = 'dxnClass';
	} else if (callType == 'moisture') {
		tabNames = ['实时含水率过程'];
		//扩展		
		showOtherClass = 'kzClass';
	} else if (callType == 'evaporation') {
		tabNames = ['日蒸发过程'];
	} else if (callType == 'groundWater') {
		tabNames = ['实时埋深过程'];
	}

	// 判断是否显示典型年
	var params = winContent.find('.params');
	// 隐藏需要判断显示的
	params.find('form>.col-md-3').hide();
	if (showOtherClass) {
		params.find('.' + showOtherClass).show();
		params.find('form>.col-md-5').removeClass('col-md-5').addClass('col-md-4');
		params.find('form').addClass('windowForm');
	} else {
		params.find('form>.col-md-4').removeClass('col-md-4').addClass('col-md-5');
		params.find('.windowForm').removeClass('windowForm');
	}

	// 设置弹出窗口 active 归属
	var allRainItem = dyamicTab.filter('.' + callType).show();
	var inNum = 0;
	allRainItem.each(function(i, n) {
		var $this = $(n);
		var tabId = $this.find('a').attr('aria-controls');
		var $tabId = $('#' + tabId);
		var $tabChildren = $tabId.children().hide();
		if (inNum == 1) {
			if (tabId.indexOf('Hour') >= 0) {
				inNum++;
			}
		}
		if (inNum == 0 || inNum == 2) {
			$this.addClass('active');
			$tabId.addClass('active');
			$tabId.show();
			$tabChildren.filter('.' + callType).show();
			inNum++;
		} else {
			$tabId.removeAttr('style');
			$tabChildren.filter('.' + callType).removeAttr('style');
		}
	});

	// 设置弹出框Tab页名字
	$('#windowContent #winTabs a').each(function(i, n) {
		var $this = $(n);
		var $parent = $this.parent();
		var tabId = $this.attr('aria-controls');
		if (i == 0) {
			$parent.addClass('active');
			$('#' + tabId, '#windowContent').addClass('active');

			if (tabNames.length == 1) {
				var haveExport = $('#' + tabId, '#windowContent').find('.dataPanel .nav-tabs .active').hasClass('haveExport');
				if (haveExport) {
					exportCsvBtn.show();
				}
			}
		} else {
			$parent.removeClass('active').removeAttr('style');
			$('#' + tabId, '#windowContent').removeAttr('style').removeClass('active');
		}
		// 如果 tabNames 只有一个，则表示只显示'日'标签
		if (tabNames.length == 1 && i == 1) {
			$parent.hide();
			$('#' + tabId, '#windowContent').hide();
		} else {
			$(n).text(tabNames[i]);
		}
	});

}